package com.grace.cms.admin.listener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.grace.system.utils.SecurityUtils;
import com.grace.cms.admin.service.ICmsUpdateService;
import com.grace.cms.common.domain.entity.CmsUpdate;
import com.grace.cms.common.event.PublicPublishEvent;
import com.grace.cms.common.model.EventModel;
import com.grace.cms.common.service.IPublicPublishListener;

@Component
public class PublicPublishListenerAdmin implements IPublicPublishListener {
    @Autowired
    private ICmsUpdateService updateService;
    @Override
    public void onApplicationEvent(PublicPublishEvent event) {
        EventModel ev=event.getEventModel();
        updateCmsUpdate(ev);
        
    }

    protected void updateCmsUpdate(EventModel ev){
        CmsUpdate cmsUpdate=new CmsUpdate(ev.getEventType().name(),ev.getEventFrom().name(),ev.getEventId(),SecurityUtils.getUsername());
        updateService.insertCmsUpdate(cmsUpdate);
    }
}
